<?php

use yii\db\Migration;

class m210222_083203_addon_flow_metadata extends Migration
{
    public function up()
    {
        /* 取消外键约束 */
        $this->execute('SET foreign_key_checks = 0');
        
        /* 创建表 */
        $this->createTable('{{%addon_flow_metadata}}', [
            'id' => "int(11) NOT NULL AUTO_INCREMENT",
            'merchant_id' => "int(11) NULL DEFAULT '0'",
            'workflow_id' => "varchar(32) NOT NULL",
            'status_id' => "varchar(32) NOT NULL",
            'key' => "varchar(64) NOT NULL",
            'value' => "text NOT NULL",
            'PRIMARY KEY (`id`)'
        ], "ENGINE=InnoDB DEFAULT CHARSET=utf8");
        
        /* 索引设置 */
        $this->createIndex('merchant_id','{{%addon_flow_metadata}}','merchant_id, workflow_id, status_id, key',1);
        
        
        /* 表数据 */
        
        /* 设置外键约束 */
        $this->execute('SET foreign_key_checks = 1;');
    }

    public function down()
    {
        $this->execute('SET foreign_key_checks = 0');
        /* 删除表 */
        $this->dropTable('{{%addon_flow_metadata}}');
        $this->execute('SET foreign_key_checks = 1;');
    }
}

